<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /* @var $this \Magento\Downloadable\Block\Catalog\Product\Links */ ?>
<?php $_linksPurchasedSeparately = $this->getLinksPurchasedSeparately(); ?>
<?php if ($this->getProduct()->isSaleable() && $this->hasLinks()):?>
    <?php $_links = $this->getLinks(); ?>
    <?php $_isRequired = $this->getLinkSelectionRequired(); ?>
    <div class="field downloads<?php if ($_isRequired) echo ' required' ?>">
        <label class="label"><span><?php echo $this->getLinksTitle() ?></span></label>
        <div class="control" id="downloadable-links-list"
             data-mage-init='{"downloadable":{
                 "linkElement":"input:checkbox[value]",
                 "allElements":"#links_all",
                 "config":<?php echo $this->getJsonConfig() ?>}
             }'
             data-container-for="downloadable-links">
            <?php foreach ($_links as $_link): ?>
                <div class="field choice" data-role="link">
                    <?php if ($_linksPurchasedSeparately): ?>
                        <input type="checkbox"
                               <?php if ($_isRequired): ?>data-validate="{'validate-one-checkbox-required-by-name':'downloadable-links-list'}" <?php endif; ?>
                               name="links[]"
                               id="links_<?php echo $_link->getId() ?>"
                               value="<?php echo $_link->getId(); ?>" <?php echo $this->getLinkCheckedValue($_link); ?> />
                    <?php endif; ?>
                    <label class="label" for="links_<?php echo $_link->getId() ?>">
                        <span><?php echo $this->escapeHtml($_link->getTitle()); ?></span>
                        <?php if ($_link->getSampleFile() || $_link->getSampleUrl()): ?>
                            <a class="sample link"
                               href="<?php echo $this->getLinkSampleUrl($_link) ?>" <?php echo $this->getIsOpenInNewWindow() ? 'target="_blank"' : ''; ?>>
                                <?php echo __('sample') ?>
                            </a>
                        <?php endif; ?>
                        <?php if ($_linksPurchasedSeparately): ?>
                            <?php echo $this->getLinkPrice($_link); ?>
                        <?php endif; ?>
                    </label>
                </div>
            <?php endforeach; ?>
            <div class="field choice downloads-all">
                <input type="checkbox"
                       data-notchecked="<?php echo __('Select all')?>"
                       data-checked="<?php echo __('Unselect all')?>"
                       id="links_all" />
                <label class="label" for="links_all"><span><?php echo __('Select all')?></span></label>
            </div>
        </div>
        <?php if ($_isRequired): ?>
            <span id="links-advice-container"></span>
        <?php endif;?>
    </div>
<?php endif; ?>
